#ifndef MARSROVER
#define MARSROVER

namespace MR{
	class MarsRoverBase{
	public:
		typedef int Direction;
		typedef int Coordinate;
		MarsRoverBase(){North = 0,East = 1,Sourth = 2, West = 3;}
		virtual ~MarsRoverBase(){}
		
		Direction North;
		Direction Sourth;
		Direction East;
		Direction West;

		static int NORTH;
		static int SOURTH;
		static int EAST;
		static int WEST;
	};
	class MarsRover:public MarsRoverBase{
	public:
		//MarsRover():MarsRoverBase();

		MarsRover():MarsRoverBase(){}
		~MarsRover(){}
		
		class Status:public MarsRoverBase{
		public:
			Status(Direction direction,Coordinate x,Coordinate y):MarsRoverBase(),x(x),y(y),direction(direction){}
			Status(){
				Status(0,0,0);
			}
			Status(Status & right){
				this->x = right.x;
				this->y = right.y;
				this->direction = right.direction;
			}
			~Status(){}
			void operator = (Status & right){
				this->x = right.x;
				this->y = right.y;
				this->direction = right.direction;
			}

			void operator = (Status * right){
				this->x = right->x;
				this->y = right->y;
				this->direction = right->direction;
			}

			bool operator == (Status & right){
				return (this->x == right.x)&&
					   (this->y == right.y)&&
					   (this->direction == right.direction);
			}
			
			int set(Coordinate _x, Coordinate _y , Direction _direction){
				this->x = _x;
				this->y = _y;
				this->direction = _direction;
			}
			
			Direction direction;
			Coordinate x;
			Coordinate y;
		};

		Status & init(Coordinate x, Coordinate y , Direction direction){
			last_status = current_status;
			current_status.set(x,y,direction);
			return current_status;
		}

		void deinit(){
			current_status.set(0,0,0);
			last_status = current_status;
		}

		Status & turnLeft(){
			last_status = current_status;
			current_status.direction = (current_status.direction+3)%4;
			return current_status;
		}

		Status & turnRight(){
			last_status = current_status;
			current_status.direction = (current_status.direction + 1) % 4;
			return current_status;
		}

		Status & NorthSourthForward(int stepNumber = 1){
			last_status = current_status;
			if(current_status.direction == this->North){
				stepNumber *= 1;
			}
			else{
				stepNumber *= -1;
			}
			current_status.y += stepNumber;
			return current_status;
		}

		Status & WestEastForward(int stepNumber = 1){
			last_status = current_status;
			if(current_status.direction == this->East){
				stepNumber *= 1;
			}
			else{
				stepNumber *= -1;
			}
			current_status.x += stepNumber;
			return current_status;
		}

		Status & moveForward(int stepNumber = 1){
			if(current_status.direction == this->North || current_status.direction == this->Sourth){
				return NorthSourthForward(stepNumber);		
			}
			else{
				return WestEastForward(stepNumber);
			}
		}
		
	private:
		Status current_status;
		Status last_status;
	};
};






#endif
